from typing import Optional

from sqlalchemy import BigInteger, DateTime, Integer, PrimaryKeyConstraint, String, func, DECIMAL
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import datetime

from config.database import Base
from utils.uuid import UUID


class CmsOrderExecute(Base):
    __tablename__ = 'cms_order_execute'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='_copy_2'),
        {'comment': '用车履约'}
    )

    id: Mapped[int] = mapped_column(BigInteger, primary_key=True, default=int(UUID().uuid()))
    state: Mapped[int] = mapped_column(Integer, comment='状态（0 失效，1 有效）')
    create_time: Mapped[datetime.datetime] = mapped_column(DateTime, comment='创建时间', server_default=func.now())
    order_id: Mapped[Optional[str]] = mapped_column(String(32), comment='单号')
    car_id: Mapped[Optional[str]] = mapped_column(String(32), comment='车辆编码')
    driver_id: Mapped[Optional[str]] = mapped_column(String(32), comment='驾驶员编码')
    rading_count: Mapped[Optional[int]] = mapped_column(Integer, comment='乘坐人数')
    reality_begin_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='实际出车时间')
    reality_end_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='实际回车时间')
    start_mileage: Mapped[float] = mapped_column(DECIMAL(10, 2), comment='任务开始里程')
    end_mileage: Mapped[float] = mapped_column(DECIMAL(10, 2), comment='任务结束里程')
    sign: Mapped[str] = mapped_column(String(32), comment='签名')
    sheet_mileage: Mapped[float] = mapped_column(DECIMAL(10, 2), comment='仪表里程')
    start_file: Mapped[str] = mapped_column(String(1024), comment='任务开始附件')
    end_file: Mapped[str] = mapped_column(String(1024), comment='任务结束附件')
    create_by: Mapped[Optional[str]] = mapped_column(String(32), comment='创建人')
    update_time: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, comment='修改时间',
                                                                     server_default=func.now(), onupdate=func.now())
    update_by: Mapped[Optional[str]] = mapped_column(String(32), comment='修改人')
    bill_type: Mapped[Optional[str]] = mapped_column(String(32), comment='结算类型 北斗系统结算 表显里程结算')
